<?php
namespace Home\Controller;
use Think\Controller;
use JPush\Model as M;
use JPush\JPushClient;
use JPush\Exception\APIConnectionException;
use JPush\Exception\APIRequestException;


class TestController extends Controller {
    public function index(){
        vendor('jpush/autoload');
        $br = '<br/>';
        $client = new JPushClient('161f1017deaf5dc1cba3e83d', 'bb3a91fe849af6cb1d754db9');
        
        try {
            $result = $client->push()
            ->setPlatform(M\all)
            ->setAudience(M\all)
            ->setNotification(M\notification('send message',
                M\android('Hi, Android', '你妹', 1, array("key1"=>"value1", "key2"=>"value2")),
                M\ios("Hi, IOS", "happy", "+1", true, array("action"=>"message", "messageID"=>"2"), "Ios8 Category")
            ))
            ->setMessage(M\message('Message Content', 'Message Title', 'Message Type', array("key1"=>"value1", "key2"=>"value2")))
            ->printJSON()
            ->send();
            
            
            echo 'Push Success.' . $br;
            echo 'sendno : ' . $result->sendno . $br;
            echo 'msg_id : ' .$result->msg_id . $br;
            echo 'Response JSON : ' . $result->json . $br;
        } catch (APIRequestException $e) {
            echo 'Push Fail.' . $br;
            echo 'Http Code : ' . $e->httpCode . $br;
            echo 'code : ' . $e->code . $br;
            echo 'message : ' . $e->message . $br;
            echo 'Response JSON : ' . $e->json . $br;
            echo 'rateLimitLimit : ' . $e->rateLimitLimit . $br;
            echo 'rateLimitRemaining : ' . $e->rateLimitRemaining . $br;
            echo 'rateLimitReset : ' . $e->rateLimitReset . $br;
        } catch (APIConnectionException $e) {
            echo 'Push Fail.' . $br;
            echo 'message' . $e->getMessage() . $br;
        }
    }
    
    public function test2(){
        phpinfo();
    }
}